#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int dist=0;

void distance(int a, float factor){
	static int speed=0;
	static int numQuietReads=0;
	float adjustedA=0;

	if(a<0)
		adjustedA=a*factor;
	else
		adjustedA=a;

			if(abs(adjustedA)>10){
				speed = adjustedA + speed;
				numQuietReads=0;
			}
			else if (abs(speed)>50){
				numQuietReads++;
					float factor = (1/numQuietReads);
					speed = speed*factor;
			}
			else
			{
				speed=0;
			}
			dist+=speed;
}

void testFactor(float fact){
	cout<<fact<<endl;
	int accel=0, hallDist=0, oneDist=0, threeDist=0, thirdOfThree=0, dDiff=0;
    ifstream hallFile("hallway.txt");
		if(!hallFile) //Always test the file open.
		{
					cout<<"Error opening output file"<<endl;
					system("pause");
		}
		while(!hallFile.eof())
		{
			   //getline(myfile,str[a][b],' ');
			   hallFile>>accel;
			   distance(accel, fact);
			   //system("pause");
		}
		
		hallDist=dist;
		dist=0;
		cout<<hallDist<<endl;
		//system ("pause");
    ifstream singleLapFile("oneLap.txt");
		if(!singleLapFile) //Always test the file open.
		{
					cout<<"Error opening output file"<<endl;
					//system("pause");
		}
		while(!singleLapFile.eof())
		{
			   //getline(myfile,str[a][b],' ');
			   singleLapFile>>accel;
			   distance(accel, fact);
			   //system("pause");
		}
		
		oneDist=dist;
		dist=0;
		cout<<oneDist<<endl;
		//system ("pause");
		
    ifstream threeLapFile("threeLaps.txt");
		if(!threeLapFile) //Always test the file open.
		{
					cout<<"Error opening output file"<<endl;
					//system("pause");
		}
		while(!threeLapFile.eof())
		{
			   //getline(myfile,str[a][b],' ');
			   threeLapFile>>accel;
			   distance(accel, fact);
			   //system("pause");
		}
		threeDist=dist;
		dist=0;
		cout<<threeDist<<endl;
		thirdOfThree=threeDist/3;
		dDiff=oneDist-thirdOfThree;
		cout<<thirdOfThree<<" is 1/3 of 3 Laps; diff "<<dDiff<<endl;
		cout<<endl;
		//system ("pause");

}

	long x_CoordLat = 4239389, y_CoordLat = -725890;
	int boundArray[48][48] =   {{0,0,0,0,0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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
									{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
									{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
									{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
									{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
									{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
									{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};



	unsigned char fillMe[24][48];




	void compressPic(){

		for(int i=0; i<24; i++){
			for(int j=0; j<48; j++){
				fillMe[i][j]=0;
			}
		}

		for(int x=0; x<48; x++){
			for(int y=0; y<48; y++){

				if(y%2){
					fillMe[x][(y-1)/2]|=boundArray[x][y];

					cout<<(int)fillMe[x][(y-1)/2];
				
					if(y!=47){
						cout<<",";
					}
					else{
						cout<<"},";
					}
				}
				else{
					if(y==0)
						cout<<"{";
					fillMe[x][y/2]|=(boundArray[x][y]<<4);
				}
				
			}
			
			if(x==47)
				cout<<"}";

			cout<<endl;
		}


		system ("pause");
	}




void main ()
{
	compressPic();

		/*testFactor(.9);
		system ("pause");

		testFactor(.8);
		system ("pause");

		testFactor(.7);
		system ("pause");

		testFactor(.6);
		system ("pause");

		testFactor(.5);
		system ("pause");

		testFactor(.45);
		system ("pause");

		testFactor(.4);
		system ("pause");

		testFactor(.35);
		system ("pause");

		testFactor(.3);
		system ("pause");

		testFactor(.25);
		system ("pause");

		testFactor(.2);
		system ("pause");

		testFactor(.15);
		system ("pause");

		testFactor(.1);
		system ("pause");

		testFactor(.05);
		system ("pause");

		testFactor(0);
		system ("pause");

		testFactor(.448);
		system ("pause");

		testFactor(.4479);
		system ("pause");

		testFactor(.4478);
		system ("pause");

		testFactor(.4477);
		system ("pause");

		testFactor(.4476);
		system ("pause");

		testFactor(.4475);
		system ("pause");

		testFactor(.4474);
		system ("pause");

		testFactor(.4473);
		system ("pause");

		testFactor(.4472);
		system ("pause");

		testFactor(.4471);
		system ("pause");*/

}




